﻿#ifndef AnimationState_Purify_H
#define AnimationState_Purify_H

#include <QObject>
#include <QColor>
#include <cmath>
#include "syringeCalculator.h"
#include "pipeGraph.h"

struct stLiquidPath{
    QVector<int>    vertex;
    double          start;
    double          end;
    QColor          color;
    bool            state;
    stLiquidPath(){
        this->start = 0;
        this->end = 0;
        this->color = QColor(255, 0, 0);
        this->state = true;
    }
    stLiquidPath(QVector<int> vertex, double start, double end, QColor color, bool state){
        this->vertex = vertex;
        this->start = start;
        this->end = end;
        this->color = color;
        this->state = state;
    }
};


class AnimationState_Purify : public QObject
{
    Q_OBJECT
public:
    AnimationState_Purify();
    ~AnimationState_Purify();

    // 设备操作
    void reset();
    void turnWheel(int num, double speed = 1);      // num>0顺时针(左转)  num<0逆时针(右转)
    void turnWheel_posi(int posi, double speed = 1);
    void turnWheel_posi(int posi, int direct, double speed = 1);
    void pushHat();
    void pressHat();
    void changeValve(int idx, bool state);
    void changeSyringe(int idx, double percentage, double speed = 1);
    void changeSyringe_dp(int idx, double dPercentage, double speed = 1);   // 百分比的变化量
    void changeSyringeSpeedTarget(int idx, double speed);            // 显示的理论速度
    void changeSyringeSpeedRealTime(int idx, double speed);          // 显示的实际速度
    void changeColumn(bool state);
    void changeDetector(bool state);
    void changeSpeedUnit(int type);
    void changePPumpState(int state);
    void changeSyringeErrorState(int idx, int state);
    void changeHeating(bool state);     // true加热 false不加热

    void updateLiquidPath();
    void setVertexEmitting(int idx, bool state);



    // 状态判断
    bool            isVertexConnect(int v1, int v2);        // 判断两个点之间的连通性
    void            printCurrentPath();                     // 打印
    QVector<QVector<int>>    getCurrentPath();              // 获取当前正在流动液体的路径

    // 属性配置
    void setColor(QMap<int, QColor> colorList);


    // 状态变更时，调用AnimationController，提供变化前和变化后的状态，然后AnimationController做动画和前端交互

signals:
    void sigReset();
    void sigWheelChanged(int posi1, int posi2, double speed, int direction);
    void sigHatPressed();
    void sigHatPushed();
    void sigValveChanged(int idx, bool state1, bool state2);
    void sigSyringeChanged(int idx, double percentage1, double percentage2, double speed);
    void sigLiquidChanged(QMap<QString, QVector<int>> pathList);


public:

    PipeGraph*      _pipeGraph = nullptr;       // 管道状态

    int             _valveNum = 15;
    QVector<bool>   _valveState;                // 阀门状态

    int             _syringeNum = 7;
    QVector<QColor> _syringeColor;
    QVector<double> _syringePercentage;         // 当前百分比
    QVector<double> _syringeSpeed_target;       // 理论速率 (默认存mm/ml，通过参数控制requestInfo返回哪种)
    QVector<double> _syringeSpeed_realtime;     // 实时速率（这两个参数是用来给用户显示的）
    QVector<int>    _syringeErrorState;         // 注射器的故障状态 -1故障 0正常

    int             _speedUnit = 1;     // 0:mm/s  1:min/ml

    QVector<double> _syringeVolumn;             // 体积

    int             _dissolveTime = 300;

    int             _wheelNum = 9;
    int             _wheelPosi;

    bool            _detector = true;                  // 检测器状态
    bool            _column = true;                    // 色谱柱状态

    int             _hatNum = 100;

    int             _gCollectContainer = 1;              // 0转盘 1溶靶罐

    int             _pPumpState = 0;            // 蠕动泵状态

    bool            _heatingState = false;      // 加热状态


};

#endif // AnimationState_Purify_H
